<template>
  <div class="success-wrap">
    <a-result
      status="success"
      :title="$t('stepForm.success.title')"
      :subtitle="$t('stepForm.success.subTitle')"
    />
    <a-space :size="16">
      <a-button key="view" type="primary">
        {{ $t('stepForm.button.view') }}
      </a-button>
      <a-button key="again" type="secondary" @click="oneMore">
        {{ $t('stepForm.button.again') }}
      </a-button>
    </a-space>
    <div class="details-wrapper">
      <a-typography-title :heading="6" style="margin-top: 0">
        {{ $t('stepForm.form.description.title') }}
      </a-typography-title>
      <div class="data-details">
        <a-typography-title :heading="6" style="margin-top: 20px">
          <!-- Use v-html to render formatted log information -->
          <span v-html="formattedLogInfo"></span>
          <a-link :href="'/task/' + data.taskId">{{
            $t('stepForm.button.view')
          }}</a-link>
          Taskid: {{ data.taskId }}
        </a-typography-title>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { defineProps, defineEmits, onMounted, computed } from 'vue';

  const props = defineProps<{
    data;
  }>();

  const emits = defineEmits(['changeStep']);

  // Use computed property to automatically update when data changes
  const formattedLogInfo = computed(() => {
    // Ensure that logInfo is a string and replace \n with HTML line breaks
    if (props.data.logInfo && typeof props.data.logInfo === 'string') {
      return props.data.logInfo.replace(/\n/g, '<br>');
    }
    return '';
  });

  const oneMore = () => {
    emits('changeStep', 1);
  };

  onMounted(() => {
    console.log('Received data:', props.data);
  });
</script>

<style scoped lang="less">
  .success-wrap {
    text-align: center;
  }

  :deep(.arco-result) {
    padding-top: 0;
  }

  .details-wrapper {
    width: 895px;
    margin-top: 54px;
    padding: 20px;
    text-align: left;
    background-color: var(--color-fill-2);
  }

  .data-details {
    text-align: left;
    margin-top: 20px;
  }
</style>
